<admintpl file="header" />
<style type="text/css">
    .imgdiv{display:inline-block; width:90px; height:90px; border:1px solid #ccc;}
	.imgdiv>img{width:100%; height: 100%}
    #fileupload {position: absolute;opacity: 0;cursor: pointer;top: 0;z-index: 1;}
    .LOGO_BTN{position: relative;display: inline-block;width:100px;background: #7e7e7e;color: #E4c217;border-radius: 4px;line-height: 26px;margin-top:10px }
	.error-info{font-size: 13px;color: red;}
	.sucess-info{font-size: 13px;color: green;}
	
</style>
	<script src="__PUBLIC__/js/upload/jquery.ui.widget.js"></script>
    <script src="__PUBLIC__/js/upload/jquery.iframe-transport.js"></script>
    <script src="__PUBLIC__/js/upload/jquery.fileupload.js"></script>
</head>
<body>
	<div class="wrap">
		<ul class="nav nav-tabs">
			<li><a href="{:U('Event/index')}">赛事列表</a></li>
			<li class="active"><a href="{:U('Event/add')}">添加赛事</a></li>
		</ul>
		<form id="event-form" method="post" class="form-horizontal js-ajax-form" action="{:U('Event/event_post')}">
			<fieldset>
				<div class="control-group">
					<label class="control-label">赛事名称</label>
					<div class="controls">
						<input type="text" name="event_name" required="required">
					</div>
				</div>
				<div class="control-group">
					<label class="control-label">赛事Logo</label>
					<div class="controls">
						<div class="imgdiv" >
                            <img id="img_url_1" src="http://bmss.pool-data.com/image/logo.png" >
                            <input id="player_photo_1" type="hidden" name="player1_photo" value="">
                        </div>
                        <div class="LOGO_BTN">上传照片<input class="fileupload" data-val="1" id="fileupload" type="file" name="files[]" data-url="{:U('Event/upload')}" multiple=""></div><span style="font-size:14px;color:#888">&nbsp;&nbsp;建议上传尺寸：300*300</span>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label">客户手机号</label>
					<div class="controls">
						<input id="customer-mobile" type="text" name="customer_mobile" required="required">
						&nbsp;<span id="customer-mobile-info"></span> 
					</div>
				</div>
				<div class="control-group">
					<label class="control-label">开球规则</label>
					<div class="controls">
						<input name="ball_rule" type="radio" value="轮流开球" checked/>轮流开球&nbsp;
						<input name="ball_rule" type="radio" value="连续开球" />连续开球&nbsp;
						<input name="ball_rule" type="radio" value="未知" />未知&nbsp;
					</div>
				</div>
                
                <div class="control-group">
					<label class="control-label">赛事类型</label>
					<div class="controls">
						<foreach name="event_type_list" item="vo">
							<input name="event_type" type="radio" value="{$vo['key']}" <if condition="$vo['key'] eq '1'">checked</if>/>{$vo['value']}&nbsp;
						</foreach>
					</div>
				</div>

				<div class="control-group">
					<label class="control-label">比赛开始时间</label>
					<div class="controls">
						<input type="text" name="begin_time" class="js-datetime"  value="{$formget.begin_time|default=''}" autocomplete="off"  required="required">
					</div>
				</div>
					<div class="control-group">
					<label class="control-label">比赛结束时间
					</label>
					<div class="controls">
						<input type="text" class="js-datetime" name="end_time" value="{$formget.end_time|default=''}" autocomplete="off" required="required">
					</div>
				</div>
				<div class="control-group">
						<label class="control-label">授权码</label>
					<div class="controls">
						<input type="text" name="auth_code" required="required">&nbsp;<span><a style="cursor: pointer;" id="get-code">生成</a></span>
					</div>
				</div>
				<input type="hidden" id="event_logo" name="event_logo" value="http://bmss.pool-data.com/image/logo.png">
			</fieldset>
			<div class="form-actions">
				<button id="event-add" type="submit" class="btn btn-primary js-ajax-submit">{:L('ADD')}</button>
				<a class="btn" href="javascript:history.back(-1);">{:L('BACK')}</a>
			</div>
		</form>
	</div>
	<script src="__PUBLIC__/js/common.js"></script>
</body>
<script type="text/javascript">
       //照片上传
    $('.fileupload').fileupload({
        dataType: 'json',
        done: function (e,data) {
        var id = $(this).attr("data-val");
        $('#img_url_'+id).attr('src',data.result.img_url);
        $('#event_logo').val(data.result.img_url);
      }
    });
    $("#customer-mobile").blur(function(){
    	var url             = "{:U('Event/checkCustomerMobile')}";
    	var customer_mobile = $(this).val();
    	$.get(url,{customer_mobile:customer_mobile},function(data){
    		if(data['status'] == 0){
    			$("#customer-mobile-info").html(data['info']);
                $("#customer-mobile-info").addClass('error-info');
    		}else{
    			$("#customer-mobile-info").html(data['info']);
                $("#customer-mobile-info").addClass('sucess-info');
    		}
            
    	})
    })
    //生成授权码

	$("#get-code").click(function(){
		var url = "{:U('Event/createAuthCode')}";
        $.get(url,function(data){
         	$('input[name="auth_code"]').val(data.auth_code);
        })
	})
</script>
</html>